import HTMLParser
import urllib
import re

urlString = "http://www.gix.se/whois.php"
urlText=[]
check=False

class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        if tag=="pre":
            check=True
                                    
    def handle_data(self, data):
        global check 
        if data!='\n' and check==True:
            if (re.search("[A][S]\d\d*", data)):
                list=re.split("[^AS0-9]+", data)
                for item in list:
                    if re.search("[A][S]\d\d*", item):
                        urlText.append(item.replace("AS", ""))
        check=False
                    
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())
filePath="ixp_members.txt"
file=open(filePath, "a")
for item in urlText:
    #print item
    print >> file, "230 %s" % item
file.close()